﻿using SosForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using SosData;

namespace UOCManager
{
    public partial class FormManager : FormDetalle
    {
        sosContext db = null;

        #region " Constructores "

        /// <summary>
        /// Constructor
        /// </summary>
        public FormManager()
        {
            InitializeComponent();
            
        }

        #endregion

        private void FormManager_Load(object sender, EventArgs e)
        {
            db = new sosContext();
            var usuarios = from u in db.Users select u;
            bindingSource.DataSource = usuarios.ToList();
            
            //var permisos = from p in db.permisosForms select p;
            //permisosFormsBindingSource.DataSource = permisos.ToList();

            //var controlesForm = from c in db.controlesForms select c;
            //controlesFormBindingSource.DataSource = controlesForm.ToList();
        }

        public override void Guardar()
        {
            if (state== System.Data.Entity.EntityState.Added)
            {
                Usuario usuario = new Usuario();
                bindingSource.EndEdit();
                usuario = (Usuario)bindingSource.Current;

                db.Users.Add(usuario);

            }
            db.SaveChanges();
            base.estadoForm(_modoForm.Navegacion);
        }
    
    }
}
